#include<bits/stdc++.h>
using namespace std;
struct Node{
	string ID;
	vector<string>web;
};
int n , m;
vector<Node>v;
int main(){
	freopen("statistic.in" , "r" , stdin);
	freopen("statistic.out" , "w" , stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n >> m;
	for(int i = 1 ; i <= m ; i++){
		string id , website;
		cin >> id >> website;
		int j;
		for(j = 0 ; j < v.size() ; j++){
			if(id == v[j] .ID){
				v[j].web.push_back(website);
				break;
			}
		}
		if(j == v.size()){
			Node nn;
			nn.ID = id;
			nn.web.push_back(website);
			v.push_back(nn);
		}
	}
	for(int i = 0 ; i < v.size() ; i++){
		cout << v[i].ID;
		for(int j = 0 ; j < v[i].web.size() ; j++){
			cout << " " << v[i].web[j];
		}
		cout << endl;
	}
	return 0;
}